home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / lalr.lha / lalr / lib / Errors.c next >
C/C++ Source or Header  |  1992-08-18  |  4KB  |  143 lines

  1. /* $Id: Errors.c,v 2.8 1992/08/17 14:35:54 grosch rel $ */
  2.  
  3. # include "Errors.h"
  4. # include <stdio.h>
  5.  
  6. # ifdef __cplusplus
  7. extern "C" {
  8. #  include "System.h"
  9. #  include "Sets.h"
  10. #  include "Idents.h"
  11. }
  12. # else
  13. #  include "System.h"
  14. #  include "Sets.h"
  15. #  include "Idents.h"
  16. # endif
  17.  
  18. static void yyExit () { Exit (1); }
  19.  
  20. void (* Errors_Exit) () = yyExit;
  21.  
  22. static void WriteHead
  23. # if defined __STDC__ | defined __cplusplus
  24.    (short yyErrorClass, tPosition yyPosition)
  25. # else
  26.    (yyErrorClass, yyPosition) short yyErrorClass; tPosition yyPosition;
  27. # endif
  28. {
  29.    WritePosition (stderr, yyPosition);
  30.    (void) fputs (": ", stderr);
  31.    switch (yyErrorClass) {
  32.    case xxFatal        : (void) fputs ("Fatal       ", stderr); break;
  33.    case xxRestriction    : (void) fputs ("Restriction ", stderr); break;
  34.    case xxError        : (void) fputs ("Error       ", stderr); break;
  35.    case xxWarning    : (void) fputs ("Warning     ", stderr); break;
  36.    case xxRepair    : (void) fputs ("Repair      ", stderr); break;
  37.    case xxNote        : (void) fputs ("Note        ", stderr); break;
  38.    case xxInformation    : (void) fputs ("Information ", stderr); break;
  39.    default        : (void) fprintf (stderr, "Error class: %d ", yyErrorClass);
  40.    }
  41. }
  42.  
  43. static void WriteTail
  44. # if defined __STDC__ | defined __cplusplus
  45.    (short yyErrorClass)
  46. # else
  47.    (yyErrorClass) short yyErrorClass;
  48. # endif
  49. {
  50.    (void) fputc ('\n', stderr);
  51.    if (yyErrorClass == xxFatal) Errors_Exit ();
  52. }
  53.  
  54. static void WriteCode
  55. # if defined __STDC__ | defined __cplusplus
  56.    (short yyErrorCode)
  57. # else
  58.    (yyErrorCode) short yyErrorCode;
  59. # endif
  60. {
  61.    switch (yyErrorCode) {
  62.    case xxNoText    : break;
  63.    case xxSyntaxError    : (void) fputs ("syntax error"        , stderr); break;
  64.    case xxExpectedTokens: (void) fputs ("expected tokens"    , stderr); break;
  65.    case xxRestartPoint    : (void) fputs ("restart point"        , stderr); break;
  66.    case xxTokenInserted    : (void) fputs ("token inserted "    , stderr); break;
  67.    default        : (void) fprintf (stderr, " error code: %d", yyErrorCode);
  68.    }
  69. }
  70.  
  71. static void WriteInfo
  72. # if defined __STDC__ | defined __cplusplus
  73.    (short yyInfoClass, char * yyInfo)
  74. # else
  75.    (yyInfoClass, yyInfo) short yyInfoClass; char * yyInfo;
  76. # endif
  77. {
  78.    (void) fputs (": ", stderr);
  79.    switch (yyInfoClass) {
  80.    case xxInteger    : (void) fprintf (stderr, "%d", * (int *)    yyInfo); break;
  81.    case xxShort        : (void) fprintf (stderr, "%d", * (short *)    yyInfo); break;
  82.    case xxCharacter    : (void) fprintf (stderr, "%c", *        yyInfo); break;
  83.    case xxString    : (void) fputs     (yyInfo, stderr);             break;
  84.    case xxSet        : WriteSet     (stderr, (tSet *)        yyInfo); break;
  85.    case xxIdent        : WriteIdent     (stderr, * (tIdent *)        yyInfo); break;
  86.    default        : (void) fprintf (stderr, "info class: %d", yyInfoClass);
  87.    }
  88. }
  89.  
  90. void ErrorMessage
  91. # if defined __STDC__ | defined __cplusplus
  92.    (short yyErrorCode, short yyErrorClass, tPosition yyPosition)
  93. # else
  94.    (yyErrorCode, yyErrorClass, yyPosition)
  95.    short yyErrorCode, yyErrorClass; tPosition yyPosition;
  96. # endif
  97. {
  98.    WriteHead (yyErrorClass, yyPosition);
  99.    WriteCode (yyErrorCode);
  100.    WriteTail (yyErrorClass);
  101. }
  102.  
  103. void ErrorMessageI
  104. # if defined __STDC__ | defined __cplusplus
  105.    (short yyErrorCode, short yyErrorClass, tPosition yyPosition, short yyInfoClass, char * yyInfo)
  106. # else
  107.    (yyErrorCode, yyErrorClass, yyPosition, yyInfoClass, yyInfo)
  108.    short yyErrorCode, yyErrorClass; tPosition yyPosition; short yyInfoClass; char * yyInfo;
  109. # endif
  110. {
  111.    WriteHead (yyErrorClass, yyPosition);
  112.    WriteCode (yyErrorCode);
  113.    WriteInfo (yyInfoClass, yyInfo);
  114.    WriteTail (yyErrorClass);
  115. }
  116.  
  117. void Message
  118. # if defined __STDC__ | defined __cplusplus
  119.    (char * yyErrorText, short yyErrorClass, tPosition yyPosition)
  120. # else
  121.    (yyErrorText, yyErrorClass, yyPosition)
  122.    char * yyErrorText; short yyErrorClass; tPosition yyPosition;
  123. # endif
  124. {
  125.    WriteHead (yyErrorClass, yyPosition);
  126.    (void) fputs (yyErrorText, stderr);
  127.    WriteTail (yyErrorClass);
  128. }
  129.  
  130. void MessageI
  131. # if defined __STDC__ | defined __cplusplus
  132.    (char * yyErrorText, short yyErrorClass, tPosition yyPosition, short yyInfoClass, char * yyInfo)
  133. # else
  134.    (yyErrorText, yyErrorClass, yyPosition, yyInfoClass, yyInfo)
  135.    char * yyErrorText; short yyErrorClass; tPosition yyPosition; short yyInfoClass; char * yyInfo;
  136. # endif
  137. {
  138.    WriteHead (yyErrorClass, yyPosition);
  139.    (void) fputs (yyErrorText, stderr);
  140.    WriteInfo (yyInfoClass, yyInfo);
  141.    WriteTail (yyErrorClass);
  142. }
  143.